import { createApp } from 'vue'
import App from './App.vue'
import { createPinia } from 'pinia'
import i18n from '~/i18n/index'
import router from '~/router/index'
import '~/router/control'
import '~/styles/index.scss'
import 'uno.css'
import 'element-plus/theme-chalk/src/message.scss'
import 'element-plus/theme-chalk/src/message-box.scss'
import 'element-plus/theme-chalk/src/button.scss'

import { IGNORE_ERROR, FILTER_ERROR, NET_ERROR } from '~/utils/const'

const app = createApp(App)
app.use(createPinia())
app.use(i18n)
app.use(router)

app.config.errorHandler = (err, vm, info) => {
  if (typeof err != 'string' || !err.startsWith('IgnorE')) {
    console.error(err, vm, info)
  }
}

app.config.warnHandler = (msg, vm, trace) => {
  if (!msg.startsWith('IgnorE')) {
    console.warn(msg, vm, trace)
  }
}

app.mount('#app')

window.addEventListener('unhandledrejection', event => {
  if (event.reason == IGNORE_ERROR || event.reason == FILTER_ERROR || event.reason == NET_ERROR) {
    event.preventDefault()
  }
})
